package ${appConfig.groupId}.service.impl;

import ${appConfig.groupId}.model.${tableConfig.domainObjectName};
import ${appConfig.groupId}.service.I${tableConfig.domainObjectName}Service;
import ${appConfig.groupId}.mapper.${tableConfig.domainObjectName}Mapper;

import javax.annotation.Resource;

public class ${tableConfig.domainObjectName}ServiceImpl implements I${tableConfig.domainObjectName}Service {
   @Resource
   private ${tableConfig.domainObjectName}Mapper ${tableConfig.domainObjectName ? uncap_first}Mapper;

   @Override
   public Boolean delete${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${primaryKey.javaShortType} ${primaryKey.javaPropertyName}) {
       int deleteCount = ${tableConfig.domainObjectName ? uncap_first}Mapper.delete${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${primaryKey.javaPropertyName});
       if(deleteCount > 0){
           return true;
       }

       return false;
   }

   @Override
   public Boolean insertOrUpdate${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${tableConfig.domainObjectName} ${tableConfig.domainObjectName ? uncap_first}) {
	   ${tableConfig.domainObjectName} _${tableConfig.domainObjectName ? uncap_first} = null;
	   int insertOrUpdateCount = 0;
	   if(_${tableConfig.domainObjectName ? uncap_first}.get${primaryKey.javaPropertyName ? cap_first}() != null){
		  _${tableConfig.domainObjectName ? uncap_first} = ${tableConfig.domainObjectName ? uncap_first}Mapper.get${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${tableConfig.domainObjectName ? uncap_first}.get${primaryKey.javaPropertyName ? cap_first}());
		  insertOrUpdateCount = ${tableConfig.domainObjectName ? uncap_first}Mapper.update${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(_${tableConfig.domainObjectName ? uncap_first});
	   }else{
		  insertOrUpdateCount = ${tableConfig.domainObjectName ? uncap_first}Mapper.insert${tableConfig.domainObjectName}(${tableConfig.domainObjectName ? uncap_first});
	   }

	   if(insertOrUpdateCount > 0){
		  return true;
	   }
	   return false;
   }

   @Override
   public ${tableConfig.domainObjectName} get${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${primaryKey.javaShortType} ${primaryKey.javaPropertyName}) {
	  return ${tableConfig.domainObjectName ? uncap_first}Mapper.get${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${primaryKey.javaPropertyName});
   }

   @Override
   public Boolean insertOrUpdate${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}Selective(${tableConfig.domainObjectName} ${tableConfig.domainObjectName ? uncap_first}) {
      ${tableConfig.domainObjectName} _${tableConfig.domainObjectName ? uncap_first} = null;
	  int insertOrUpdateCount = 0;
	  if(_${tableConfig.domainObjectName ? uncap_first}.get${primaryKey.javaPropertyName ? cap_first}() != null){
	    _${tableConfig.domainObjectName ? uncap_first} = ${tableConfig.domainObjectName ? uncap_first}Mapper.get${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}(${tableConfig.domainObjectName ? uncap_first}.get${primaryKey.javaPropertyName ? cap_first}());
	    insertOrUpdateCount = ${tableConfig.domainObjectName ? uncap_first}Mapper.update${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}Selective(_${tableConfig.domainObjectName ? uncap_first});
	  }else{
	    insertOrUpdateCount = ${tableConfig.domainObjectName ? uncap_first}Mapper.insert${tableConfig.domainObjectName}Selective(${tableConfig.domainObjectName ? uncap_first});
	  }

	  if(insertOrUpdateCount > 0){
	    return true;
	  }
	  return false;
   }
}
